package de.playmee.tasks;

import android.os.AsyncTask;
import de.playmee.enums.Result;
import de.playmee.handler.AccountHandler;

/**
 * Asynchronous task that checks if the user account exists. Upon finishing,
 * it notifies the indicated {@AccountCheckedListener}.
 */
public class CheckAccountTask extends AsyncTask<Void, Void, Void> {
	
	private AccountCheckedListener checkedListener;
	private AccountHandler aHandler;
	private String username;
	private String password;
	private Result result;
	
	public CheckAccountTask(AccountHandler aHandler, String username, String password,
			AccountCheckedListener checkedListener) {
		this.aHandler = aHandler;
		this.username = username;
		this.password = password;
		this.checkedListener = checkedListener;
	}

	@Override
	protected Void doInBackground(Void... params) {	
		result = aHandler.checkAccount(username, password);
		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		checkedListener.onAccoutChecked(this.result);
	}
	
	public interface AccountCheckedListener {
		public void onAccoutChecked(Result result);
	}
}